package com.zhenmyan.secdeal.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * description:
 *
 * @author 颜真明
 * @date 2023/5/15  9:46
 */
@Service
@Slf4j
public class MQDirectSender {

    private static final String DIRECT_EXCHANGE = "direct_exchange";

    private static final String ROUTING_KEY_1 = "routing_key_1";

    private static final String ROUTING_KEY_2 = "routing_key_2";

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * direct模式
     *
     * @param msg
     */
    public void send1(Object msg) {
        log.info("Direct模式发送消息：" + msg);
        rabbitTemplate.convertAndSend(DIRECT_EXCHANGE,ROUTING_KEY_1, msg);
    }

    /**
     * direct模式
     *
     * @param msg
     */
    public void send2(Object msg) {
        log.info("Direct模式发送消息：" + msg);
        rabbitTemplate.convertAndSend(DIRECT_EXCHANGE,ROUTING_KEY_2, msg);
    }

}
